package com.kyh.properties;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

public class AppProps {
	
	private static Properties properties = null;
	
	private static AppProps instance;
	private AppProps(){}
	public static AppProps getInstance() {
		if (instance == null) {
			instance = new AppProps();
			properties = new Properties();
			InputStream in = null;
			try {
				in = AppProps.class.getResourceAsStream("/project.properties");
				BufferedReader bf = new BufferedReader(new InputStreamReader(in));
				properties.load(bf);
				in.close();
				
//				projectname = new String(properties.getProperty("projectname").getBytes("ISO-8859-1"), "utf-8");
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				if (in != null) {
					try {
						in.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
		}
		return instance;
	}
	
	public static String get(String key) {
		if (instance == null) {
			instance = new AppProps();
			properties = new Properties();
			InputStream in = null;
			try {
				in = AppProps.class.getResourceAsStream("/project.properties");
				BufferedReader bf = new BufferedReader(new InputStreamReader(in));
				properties.load(bf);
				in.close();
				
//				projectname = new String(properties.getProperty("projectname").getBytes("ISO-8859-1"), "utf-8");
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				if (in != null) {
					try {
						in.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
		}
		
		return properties.getProperty(key);
	}
}
